//
//  main.m
//  fmdbDemo
//
//  Created by rp.wang on 2017/9/21.
//  Copyright © 2017年 rp.wang. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "DBAccess.h"
#import "infoModel.h"


int main(int argc, const char * argv[]) {
    @autoreleasepool {
        // insert code here...
        DBAccess *dbAccess = [DBAccess sharedInstance];
        
        //打开数据库
        [dbAccess OpenServe];
        
        NSArray *lsList = [dbAccess readAllData];
        NSLog(@"\n\nthe list count is:%ld",lsList.count);
        if(lsList.count == 0)
        {
            //初始化Model,在项目中，Model的数据由服务器返回
            infoModel *Modle = [[infoModel alloc]init];
            Modle.ID = @"1000";
            Modle.userid = @"1008611";
            Modle.nickName = @"隔壁老王";
            Modle.sex = @"1";
            Modle.department = @"中国最神秘的部门:相关部门";
            //插入数据
            [dbAccess insertdatafortableName:Modle];
        }
        //添加字段 个人头像
        [dbAccess addstringfortbale:infotableName addSrting:@"userimg"];
        //查询userid
        NSString *userid = [dbAccess getmydepartmentStr:@"userid"];
        //查询昵称
        NSString *nickNameStr = [dbAccess getmydepartmentStr:@"nickName"];
        //查询部门信息
        NSString *departmentStr = [dbAccess getmydepartmentStr:@"department"];
        NSLog(@"\n======查询用户的姓名为:%@,\n用户的昵称为:%@,\n部门信息为:%@",userid,nickNameStr,departmentStr);

        //delete table
//        if([dbAccess deletetable])
//        {
//            printf("\n\ndelete the table  success");
//        }else
//        {
//            printf("\n\ndelete the table  failed");
//        }
//        [dbAccess deleteMyserver];
        
        [dbAccess modifyupdateName:@"nickName" newName:@"原来是这样的啊" userid:Id];
        [dbAccess modifyupdateName:@"userimg" newName:@"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1506080638485&di=e9ef56882a4b91db15e9fdd5cf4cf6b9&imgtype=0&src=http%3A%2F%2Fc.hiphotos.baidu.com%2Fzhidao%2Fpic%2Fitem%2F1f178a82b9014a909461e9baa1773912b31bee5e.jpg" userid:Id];
        NSLog(@"修改后的头像:%@",[dbAccess getmydepartmentStr:@"userimg"]);
        
        
        [dbAccess getcellNumberData:Id];
NSLog(@"Hello, World!");
    }
    return 0;
}


